package user

import (
	"context"
	"gf-xb-api/internal/model/dto"
	"gf-xb-api/internal/service"
	"gf-xb-api/utility/xpointer"

	"github.com/gogf/gf/v2/util/gconv"

	v1 "gf-xb-api/api/user/v1"
)

func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) {
	var bFalse = xpointer.GetPointer(false)

	var in *dto.UserCreateInput

	if err := gconv.Struct(req, &in); err != nil {
		return (*v1.CreateRes)(bFalse), err
	}

	output, err := service.User().Create(ctx, *in)
	if err != nil {
		return (*v1.CreateRes)(bFalse), err
	}

	return (*v1.CreateRes)(&output), nil
}
